//
//  PowerMoveController.m
//  League
//
//  Created by JackChen on 2018/2/13.
//  Copyright © 2018年 ciyuanjuzhen. All rights reserved.
//

#import "PowerMoveController.h"
#import "UserInfomation.h"

@interface PowerMoveController ()

@property (weak, nonatomic) IBOutlet UILabel *noticeLabel;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *buttonOpreation;

@end

@implementation PowerMoveController

- (void)viewDidLoad {
    [super viewDidLoad];
    if (self.operationState == UndoOperation) {
        self.titleLabel.text = @"Undo";
        [self.buttonOpreation setTitle:@"Undo For 1 Leagua Ticket" forState:UIControlStateNormal];
    }
    self.noticeLabel.text = [NSString stringWithFormat:@"%@ will NOT be noticed that you made a Power Move unless you chose to let him know with a message", self.model.userName == nil ? @"Some One" : self.model.userName];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)powerMoveAction:(UIButton *)sender {
    [self likeRequestWithTargetId:self.model];
}

- (IBAction)dismissAction:(UIButton *)sender {
    self.retureBlock();
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)likeRequestWithTargetId:(CustomerModel *)model {
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    CustomerModel *custmerModel = model;
    if (custmerModel.pk != nil) {
        [parameters setObject:custmerModel.pk forKey:@"targetCustomerId"];
    }
    if ([UserInfomation shareManager].pk != nil) {
        [parameters setObject:[UserInfomation shareManager].pk forKey:@"requestCustomerId"];
    }
    if (self.operationState == PowerMoveOperation) {
        [parameters setObject:@(3) forKey:@"operate"];
    } else {
        [parameters setObject:@(4) forKey:@"operate"];
    }
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kHomeLike];
    NSLog(@"urlStr:%@",urlStr);
    [DataContrller PostRequestUrl:urlStr Param:parameters requestSuccess:^(NSDictionary *backDic) {
        [self refreshStop];
        NSLog(@"backDic:%@",backDic);
        if ([backDic[@"returnCode"] integerValue] == 200) {
            self.retureBlock();
            self.powerMove();
            [self dismissViewControllerAnimated:YES completion:nil];
        } else {
            [self showAlert:backDic[@"msg"]];
        }
    } requestFail:^(NSString *backErrorStr) {
        NSLog(@"backErrorStr:%@",backErrorStr);
        [self showAlert:backErrorStr];
    }];
    
}

@end
